<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>产品图集 - Ubike自行车及滑板车产品展示 | 外贸批发</title>
    <meta name="description" content="Ubike产品图集展示高品质自行车、电动滑板车等运动产品。详细产品图片、规格参数，支持外贸批发采购。">
    <meta name="keywords" content="自行车产品,电动滑板车,产品图集,外贸批发,运动器材,中国制造">
    <meta name="robots" content="index, follow">
    <link rel="canonical" href="https://ubike.com/products">
    
    <!-- Open Graph Meta Tags -->
    <meta property="og:title" content="Ubike产品图集 - 自行车及滑板车产品展示">
    <meta property="og:description" content="高品质自行车、电动滑板车等运动产品外贸批发">
    <meta property="og:type" content="website">
    <meta property="og:url" content="https://ubike.com/products">
    <meta property="og:image" content="/static/tp/Logo.png">
    
    <!-- Schema.org Markup -->
    <script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": "CollectionPage",
        "name": "Ubike产品图集",
        "description": "自行车及滑板车产品展示",
        "url": "https://ubike.com/products",
        "mainEntity": {
            "@type": "ItemList",
            "numberOfItems": 50,
            "itemListElement": []
        }
    }
    </script>
    
    <link rel="stylesheet" href="/static/css/style.css">
    <link rel="stylesheet" href="/static/css/products.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <script src="/static/js/script.js"></script>
</head>
<body>
    <!-- 头部区域 -->
    <header class="header">
        <div class="wrap">
            <!-- 导航菜单 -->
            <nav class="main-nav">
                <div class="nav-container">
                    <div class="logo">
                        <a href="/">
                            <img src="/static/tp/Logo.png" alt="ubike">
                        </a>
                    </div>
                    <ul class="nav-menu">
                        <li><a href="/">首页</a></li>
                        <li><a href="/about">关于我们</a></li>
                        <li>
                            <a href="#" onclick="alert('特色服务页面正在开发中...')">特色服务 <i class="fas fa-chevron-down"></i></a>
                            <ul class="dropdown">
                                <li><a href="#" onclick="alert('产品定制页面正在开发中...')">产品定制</a></li>
                                <li><a href="#" onclick="alert('物流配送页面正在开发中...')">物流配送</a></li>
                            </ul>
                        </li>
                        <li class="active">
                            <a href="/products">产品图集</a>
                        </li>
                        <li>
                            <a href="/blog">行业资讯</a>
                        </li>
                        <li>
                            <a href="/contact">联系我们</a>
                        </li>
                    </ul>
                    <div class="nav-right">
                        <div class="search-box">
                            <input type="text" placeholder="搜索产品..." id="global-search">
                            <button><i class="fas fa-search"></i></button>
                        </div>
                        <div class="contact-info">
                            <span class="email"><i class="fas fa-envelope"></i> h3444850160@gmail.com</span>
                        </div>
                    </div>
                </div>
            </nav>
        </div>
    </header>

    <!-- 页面标题 -->
    <section class="page-title">
        <div class="wrap">
            <h1>产品图集</h1>
            <p>发现优质自行车及相关产品</p>
        </div>
    </section>

    <!-- 产品内容 -->
    <section class="products-container">
        <div class="wrap">
            <!-- 搜索框 -->
            <div class="search-box">
                <input type="text" id="product-search" placeholder="搜索产品名称或描述...">
                <button onclick="searchProducts()"><i class="fas fa-search"></i></button>
            </div>
            
            <!-- 筛选工具栏 -->
            <div class="filter-toolbar">
                <!-- 分类筛选 -->
                <div class="filter-section">
                    <h3>产品分类</h3>
                    <div class="category-filter" id="category-filter">
                        <button class="category-btn active" onclick="filterProducts('all')">全部产品</button>
                        <!-- 分类按钮将通过JavaScript动态生成 -->
                    </div>
                </div>
                
                <!-- 价格区间筛选 -->
                <div class="filter-section">
                    <h3>价格区间</h3>
                    <div class="price-filter">
                        <div class="price-inputs">
                            <input type="number" id="min-price" placeholder="最低价" min="0">
                            <span>至</span>
                            <input type="number" id="max-price" placeholder="最高价" min="0">
                            <button onclick="applyPriceFilter()">确定</button>
                            <button onclick="clearPriceFilter()" class="clear-btn">清除</button>
                        </div>
                        <div class="price-presets">
                            <button class="price-preset" onclick="setPriceRange(0, 100)">¥0-100</button>
                            <button class="price-preset" onclick="setPriceRange(100, 500)">¥100-500</button>
                            <button class="price-preset" onclick="setPriceRange(500, 1000)">¥500-1000</button>
                            <button class="price-preset" onclick="setPriceRange(1000, 5000)">¥1000-5000</button>
                            <button class="price-preset" onclick="setPriceRange(5000, 999999)">¥5000以上</button>
                        </div>
                    </div>
                </div>
                
                <!-- 排序选项 -->
                <div class="filter-section">
                    <h3>排序方式</h3>
                    <div class="sort-options">
                        <select id="sort-select" onchange="sortProducts()">
                            <option value="default">默认排序</option>
                            <option value="price-asc">价格从低到高</option>
                            <option value="price-desc">价格从高到低</option>
                            <option value="name-asc">名称A-Z</option>
                            <option value="name-desc">名称Z-A</option>
                            <option value="sales-desc">销量最高</option>
                            <option value="stock-desc">库存最多</option>
                        </select>
                    </div>
                </div>
            </div>
            
            <!-- 筛选结果统计 -->
            <div class="filter-stats" id="filter-stats">
                <span id="result-count">正在加载...</span>
                <span id="active-filters" class="active-filters"></span>
            </div>
            
            <!-- 产品网格 -->
            <div id="products-grid" class="products-grid">
                <div class="loading">
                    <i class="fas fa-spinner fa-spin" style="font-size: 48px; margin-bottom: 20px;"></i>
                    <p>正在加载产品数据...</p>
                </div>
            </div>
        </div>
    </section>

    <!-- 页脚 -->
    <footer class="footer">
        <div class="wrap">
            <p>&copy; 2025 ubike. 保留所有权利</p>
        </div>
    </footer>

    <script>
        // 产品管理类
        class ProductViewer {
            constructor() {
                this.baseUrl = '/api/products';
                this.products = [];
                this.filteredProducts = [];
                this.currentCategory = 'all';
                this.searchQuery = '';
                this.minPrice = null;
                this.maxPrice = null;
                this.sortBy = 'default';
                this.activeFilters = [];
                this.init();
            }

            async init() {
                await this.loadProducts();
                this.setupEventListeners();
            }

            // 加载产品数据
            async loadProducts() {
                try {
                    const response = await fetch(this.baseUrl);
                    if (!response.ok) {
                        throw new Error(`HTTP error! status: ${response.status}`);
                    }

                    const result = await response.json();
                    if (result.success) {
                        this.products = result.data.products || [];
                        this.filteredProducts = [...this.products];
                        this.renderProducts();
                        this.renderCategories();
                        this.updateFilterStats();
                    } else {
                        this.showError('加载产品失败: ' + result.message);
                    }
                } catch (error) {
                    console.error('加载产品失败:', error);
                    this.showError('网络错误，请稍后重试');
                }
            }

            // 渲染产品列表
            renderProducts() {
                const grid = document.getElementById('products-grid');
                
                if (this.filteredProducts.length === 0) {
                    grid.innerHTML = `
                        <div style="grid-column: 1 / -1; text-align: center; padding: 60px 20px; color: #666;">
                            <i class="fas fa-bicycle" style="font-size: 48px; margin-bottom: 20px;"></i>
                            <h3>暂无产品</h3>
                            <p>当前筛选条件下没有找到产品</p>
                        </div>
                    `;
                    return;
                }

                grid.innerHTML = this.filteredProducts.map(product => this.createProductCard(product)).join('');
            }

            // 创建产品卡片
            createProductCard(product) {
                const defaultImage = '/static/tp/bike1.jpg';
                const imageUrl = product.imageUrl || defaultImage;
                
                return `
                    <div class="product-card">
                        <div class="product-image">
                            <img src="${imageUrl}" alt="${product.name}" 
                                 onerror="this.src='${defaultImage}'">
                        </div>
                        <div class="product-info">
                            <span class="product-category">${product.category || '未分类'}</span>
                            <h3 class="product-name">${product.name}</h3>
                            <p class="product-description">${product.description || '暂无描述'}</p>
                            <div class="product-price">¥${product.price || '0.00'}</div>
                            <div style="font-size: 12px; color: #999;">
                                库存: ${product.stockQuantity || 0} | 销量: ${product.salesCount || 0}
                            </div>
                        </div>
                    </div>
                `;
            }

            // 渲染分类筛选
            renderCategories() {
                const categories = [...new Set(this.products.map(p => p.category).filter(Boolean))];
                const filterContainer = document.getElementById('category-filter');
                
                categories.forEach(category => {
                    const button = document.createElement('button');
                    button.className = 'category-btn';
                    button.textContent = category;
                    button.onclick = () => this.filterProducts(category);
                    filterContainer.appendChild(button);
                });
            }

            // 筛选产品
            filterProducts(category) {
                this.currentCategory = category;
                
                // 更新按钮状态
                document.querySelectorAll('.category-btn').forEach(btn => {
                    btn.classList.remove('active');
                });
                event.target.classList.add('active');

                this.applyFilters();
            }

            // 搜索产品
            searchProducts() {
                this.searchQuery = document.getElementById('product-search').value.toLowerCase();
                this.applyFilters();
            }

            // 应用价格筛选
            applyPriceFilter() {
                const minPrice = document.getElementById('min-price').value;
                const maxPrice = document.getElementById('max-price').value;
                
                this.minPrice = minPrice ? parseFloat(minPrice) : null;
                this.maxPrice = maxPrice ? parseFloat(maxPrice) : null;
                
                // 验证价格范围
                if (this.minPrice !== null && this.maxPrice !== null && this.minPrice > this.maxPrice) {
                    alert('最低价格不能高于最高价格');
                    return;
                }
                
                this.applyFilters();
            }

            // 清除价格筛选
            clearPriceFilter() {
                document.getElementById('min-price').value = '';
                document.getElementById('max-price').value = '';
                this.minPrice = null;
                this.maxPrice = null;
                
                // 清除预设按钮的激活状态
                document.querySelectorAll('.price-preset').forEach(btn => {
                    btn.classList.remove('active');
                });
                
                this.applyFilters();
            }

            // 设置价格区间预设
            setPriceRange(min, max) {
                document.getElementById('min-price').value = min;
                document.getElementById('max-price').value = max;
                
                // 更新预设按钮状态
                document.querySelectorAll('.price-preset').forEach(btn => {
                    btn.classList.remove('active');
                });
                event.target.classList.add('active');
                
                this.applyPriceFilter();
            }

            // 排序产品
            sortProducts() {
                const sortSelect = document.getElementById('sort-select');
                this.sortBy = sortSelect.value;
                this.applyFilters();
            }

            // 应用所有筛选条件
            applyFilters() {
                this.filteredProducts = this.products.filter(product => {
                    // 分类筛选
                    const categoryMatch = this.currentCategory === 'all' || product.category === this.currentCategory;
                    
                    // 搜索筛选
                    const searchMatch = !this.searchQuery || 
                        product.name.toLowerCase().includes(this.searchQuery) ||
                        (product.description && product.description.toLowerCase().includes(this.searchQuery));
                    
                    // 价格筛选
                    const price = parseFloat(product.price) || 0;
                    const priceMatch = (this.minPrice === null || price >= this.minPrice) && 
                                     (this.maxPrice === null || price <= this.maxPrice);
                    
                    return categoryMatch && searchMatch && priceMatch;
                });
                
                // 应用排序
                this.applySorting();
                
                this.renderProducts();
                this.updateFilterStats();
                this.updateActiveFilters();
            }

            // 应用排序
            applySorting() {
                switch (this.sortBy) {
                    case 'price-asc':
                        this.filteredProducts.sort((a, b) => (parseFloat(a.price) || 0) - (parseFloat(b.price) || 0));
                        break;
                    case 'price-desc':
                        this.filteredProducts.sort((a, b) => (parseFloat(b.price) || 0) - (parseFloat(a.price) || 0));
                        break;
                    case 'name-asc':
                        this.filteredProducts.sort((a, b) => a.name.localeCompare(b.name, 'zh-CN'));
                        break;
                    case 'name-desc':
                        this.filteredProducts.sort((a, b) => b.name.localeCompare(a.name, 'zh-CN'));
                        break;
                    case 'sales-desc':
                        this.filteredProducts.sort((a, b) => (b.salesCount || 0) - (a.salesCount || 0));
                        break;
                    case 'stock-desc':
                        this.filteredProducts.sort((a, b) => (b.stockQuantity || 0) - (a.stockQuantity || 0));
                        break;
                    default:
                        // 默认排序（保持原始顺序）
                        break;
                }
            }

            // 更新筛选统计信息
            updateFilterStats() {
                const resultCount = document.getElementById('result-count');
                resultCount.textContent = `找到 ${this.filteredProducts.length} 个产品（共 ${this.products.length} 个）`;
            }

            // 更新活动筛选标签
            updateActiveFilters() {
                const activeFiltersContainer = document.getElementById('active-filters');
                activeFiltersContainer.innerHTML = '';
                
                this.activeFilters = [];
                
                // 分类筛选标签
                if (this.currentCategory !== 'all') {
                    this.activeFilters.push({
                        type: 'category',
                        label: `分类: ${this.currentCategory}`,
                        clear: () => {
                            this.filterProducts('all');
                            document.querySelectorAll('.category-btn')[0].classList.add('active');
                        }
                    });
                }
                
                // 价格筛选标签
                if (this.minPrice !== null || this.maxPrice !== null) {
                    let priceLabel = '价格: ';
                    if (this.minPrice !== null && this.maxPrice !== null) {
                        priceLabel += `¥${this.minPrice}-${this.maxPrice}`;
                    } else if (this.minPrice !== null) {
                        priceLabel += `¥${this.minPrice}以上`;
                    } else {
                        priceLabel += `¥${this.maxPrice}以下`;
                    }
                    
                    this.activeFilters.push({
                        type: 'price',
                        label: priceLabel,
                        clear: () => this.clearPriceFilter()
                    });
                }
                
                // 搜索筛选标签
                if (this.searchQuery) {
                    this.activeFilters.push({
                        type: 'search',
                        label: `搜索: "${this.searchQuery}"`,
                        clear: () => {
                            document.getElementById('product-search').value = '';
                            this.searchQuery = '';
                            this.applyFilters();
                        }
                    });
                }
                
                // 排序筛选标签
                if (this.sortBy !== 'default') {
                    const sortLabels = {
                        'price-asc': '价格从低到高',
                        'price-desc': '价格从高到低',
                        'name-asc': '名称A-Z',
                        'name-desc': '名称Z-A',
                        'sales-desc': '销量最高',
                        'stock-desc': '库存最多'
                    };
                    
                    this.activeFilters.push({
                        type: 'sort',
                        label: `排序: ${sortLabels[this.sortBy]}`,
                        clear: () => {
                            document.getElementById('sort-select').value = 'default';
                            this.sortBy = 'default';
                            this.applyFilters();
                        }
                    });
                }
                
                // 渲染筛选标签
                this.activeFilters.forEach(filter => {
                    const tag = document.createElement('span');
                    tag.className = 'active-filter-tag';
                    tag.innerHTML = `
                        ${filter.label}
                        <button class="remove-filter" onclick="${filter.clear.toString().replace(/\n/g, ' ')}">&times;</button>
                    `;
                    activeFiltersContainer.appendChild(tag);
                });
            }

            // 显示错误信息
            showError(message) {
                const grid = document.getElementById('products-grid');
                grid.innerHTML = `
                    <div class="error-message" style="grid-column: 1 / -1;">
                        <i class="fas fa-exclamation-triangle" style="font-size: 48px; margin-bottom: 20px;"></i>
                        <h3>加载失败</h3>
                        <p>${message}</p>
                        <button onclick="productViewer.loadProducts()" 
                                style="margin-top: 15px; padding: 10px 20px; background: #8B4513; color: white; border: none; border-radius: 5px; cursor: pointer;">
                            重新加载
                        </button>
                    </div>
                `;
            }

            // 设置事件监听器
            setupEventListeners() {
                // 搜索框输入事件
                document.getElementById('product-search').addEventListener('input', () => {
                    this.searchProducts();
                });

                // 搜索框回车事件
                document.getElementById('product-search').addEventListener('keypress', (e) => {
                    if (e.key === 'Enter') {
                        this.searchProducts();
                    }
                });

                // 价格输入框回车事件
                document.getElementById('min-price').addEventListener('keypress', (e) => {
                    if (e.key === 'Enter') {
                        this.applyPriceFilter();
                    }
                });

                document.getElementById('max-price').addEventListener('keypress', (e) => {
                    if (e.key === 'Enter') {
                        this.applyPriceFilter();
                    }
                });
            }
        }

        // 全局函数
        function searchProducts() {
            productViewer.searchProducts();
        }

        function filterProducts(category) {
            productViewer.filterProducts(category);
        }

        function applyPriceFilter() {
            productViewer.applyPriceFilter();
        }

        function clearPriceFilter() {
            productViewer.clearPriceFilter();
        }

        function setPriceRange(min, max) {
            productViewer.setPriceRange(min, max);
        }

        function sortProducts() {
            productViewer.sortProducts();
        }

        // 初始化产品查看器
        const productViewer = new ProductViewer();
    </script>
</body>
</html>